{% extends 'base.html' %}
{% block title %}编辑个人信息{% endblock %}

{% block main %}
    <div class="container mt-4" style="max-width: 600px;">
        <h2 class="text-center mb-4">编辑个人信息</h2>
        <form method="post" enctype="multipart/form-data">
            {% csrf_token %}
            <div class="mb-3">
                <label class="form-label">用户头像</label>
                <div class="mb-2">
                    {% if profile.avatar %}
                        <img src="{{ profile.avatar.url }}" width="100" height="100" class="rounded-circle" alt="头像">
                    {% else %}
                        <img src="{% static 'image/avatar.webp' %}" width="100" height="100" class="rounded-circle"
                             alt="默认头像">
                    {% endif %}
                </div>
                <input type="file" class="form-control" name="avatar" accept="image/*">
            </div>
            <!-- 昵称 -->
            <div class="mb-3">
                <label for="nickname" class="form-label">用户昵称</label>
                <input type="text"
                       class="form-control"
                       id="nickname"
                       name="nickname"
                       value="{{ profile.nickname }}">
            </div>

            <!-- 性别 -->
            <div class="mb-3">
                <label for="gender" class="form-label">性别</label>
                <select class="form-select" id="gender" name="gender">
                    <option value="" {% if not profile.gender %}selected{% endif %}>未选择</option>
                    <option value="male" {% if profile.gender == 'male' %}selected{% endif %}>男</option>
                    <option value="female" {% if profile.gender == 'female' %}selected{% endif %}>女</option>
                </select>
            </div>

            <!-- 个人简介 -->
            <div class="mb-3">
                <label for="bio" class="form-label">个人简介</label>
                <textarea class="form-control"
                          id="bio"
                          name="bio"
                          rows="3"
                          placeholder="这个人很懒，什么也没有留下">{% if profile.bio.strip %}{{ profile.bio }}{% else %}
                    这个人很懒，什么也没有留下{% endif %}
                </textarea>
            </div>

            <!-- 所在地区 -->
            <div class="mb-3">
                <label for="region" class="form-label">所在地区</label>
                <input type="text"
                       class="form-control"
                       id="region"
                       name="region"
                       value="{{ profile.region }}">
            </div>

            <!-- 出生日期 -->
            <div class="mb-3">
                <label for="birthday" class="form-label">出生日期</label>
                <input type="date"
                       class="form-control"
                       id="birthday"
                       name="birthday"
                       value="{{ profile.birthday|date:'Y-m-d' }}">
            </div>
            <!-- 提交按钮 -->
            <div class="d-flex justify-content-between w-100">
                <button type="submit" class="btn btn-warning">保存修改</button>
                <a href="{% url 'baiauth:profile' %}" class="btn btn-outline-secondary">返回（不保存）</a>
            </div>
        </form>
    </div>
{% endblock %}